$(function () {
  //----------------------------整改过程------------------------------

  // 打开窗口
  // $('.earlyWaringRectify-pop').addClass('is-visible3');
  $('#earlyWarningModal').on('click', '.earlyWaringRectify-trigger', function (event) {
    event.preventDefault();
    $('.earlyWaringRectify-pop').addClass('is-visible3');
    var $this = $(this);
    var onlyvalue = $this.attr('onlyvalue');
    console.log(onlyvalue)
    // 将获取的数据每页分为三条
    var ret = getThreeColorGetRectifyByOnlyValue({
      onlyValue: onlyvalue
    });
    ret.then(function (data) {
      console.log(data);
      var data = data.data;
      var resultArr = [];
      $('.swiper-wrapper').html('');
      $('.swiper-slide').find('.threeColor').find('.rectifyPhotoStyle li').html('');
      var mLength = data.length % 3;
      if (mLength == 0) {
        for (var i = 0; i < data.length; i += 3) {
          resultArr.push(data.slice(i, i + 3).reverse());
        }
      } else if (mLength == 1) {
        resultArr.push(data.slice(0, 1));
        for (var i = 1; i < data.length; i += 3) {
          resultArr.push(data.slice(i, i + 3).reverse());
        }
      } else if (mLength == 2) {
        resultArr.push(data.slice(0, 2).reverse());
        for (var i = 2; i < data.length; i += 3) {
          resultArr.push(data.slice(i, i + 3).reverse());
        }
      }

      var appearTimeLast = $this.parent().siblings().eq(8).text();
      var rectificationStr = $this.parent().siblings().eq(7).text();
      var unit = $this.parent().siblings().eq(3).text();
      var manager = $this.parent().siblings().eq(2).text();
      $('#earlyWaringRectifyModal .textContent .unitStr').text(unit);
      $('#earlyWaringRectifyModal .textContent .people').text(manager);
      $('#earlyWaringRectifyModal .textContent .rectification').text(rectificationStr);
      $('#earlyWaringRectifyModal .textContent .date').text(appearTimeLast);
      console.log(resultArr);
      var patrolSum = data.length;
      for (var i = 0; i < resultArr.length; i++) {
        $('.swiper-wrapper').append('<div class="swiper-slide"><div class="threeColor"></div></div>');
        for (var j = 0; j < 3; j++) {
          if (resultArr[i][j]) {
            var num = resultArr[i][j].count;
            var appearTime = resultArr[i][j].threeColorWarning.appearTime;
            appearTime = moment(appearTime).format('YYYY-MM-DD HH:mm:ss');
            var appearPeople = resultArr[i][j].threeColorWarning.appearPeople;
            var levelisk = resultArr[i][j].threeColorWarning.levelisk;
            var leveliskStr = '';
            patrolSum += num;
            if (levelisk == 3) {
              leveliskStr = '高危';
            } else if (levelisk == 2) {
              leveliskStr = '较大';
            } else if (levelisk <= 1) {
              leveliskStr = '一般';
            }
            // 整改过程渲染图片
            var imgurlArr = [];
            imgurlArr = resultArr[i][j].url;
            console.log(imgurlArr)
            var liHtml = '';
            if (imgurlArr) {
              for (var k = 0; k < imgurlArr.length; k++) {
                liHtml += '<li><a href="' + imgurlArr[k] + '" class="galpop" data-galpop-group="gallery"><img class="pic img-responsive opacity1" src="' + imgurlArr[k] + '"></a></li>';
              }
            }

            $('.swiper-slide').eq(i).find('.threeColor').append(earlyWaringRectifyHtmlFunc(levelisk, num, appearTime, leveliskStr, appearPeople, liHtml));


          }
        }
      }
      $('#earlyWaringRectifyModal .textContent .sum').text(patrolSum + '次');
      $('.swiper-notification').remove();
      // var translateMove = (1-resultArr.length)*1040;
      $('.swiper-wrapper').css('transform', 'translate3d(0px, 0px, 0px)')
      var swiper = new Swiper('.swiper-container', {
        navigation: {
          prevEl: '.swiper-button-next',
          nextEl: '.swiper-button-prev',
        },
      });

      $('.galpop').galpop();
    }).catch(function (err) {
      console.log(err);
    });

  });

  // 关闭窗口
  $('.earlyWaringRectify-pop').on('click', function (event) {
    if ($(event.target).is('.cd-popup-close') || $(event.target).is('.earlyWaringRectify-pop')) {
      event.preventDefault();
      $(this).removeClass('is-visible3');
    }
  });
  // 将整改过程的内容封装
  function earlyWaringRectifyHtmlFunc(levelisk, num, date, rank, name, liHtml) {
    var riskClase, place;
    if (levelisk == 3) {
      riskClase = 'highRisk';
      place = '高危';
    } else if (levelisk == 2) {
      riskClase = 'mediumRisk';
      place = '较大';
    } else {
      riskClase = 'generalRisk';
      place = '一般';
    }
    var earlyWaringRectifyHtml = ['<div class="' + riskClase + ' threeColorList">',
      '  <div class="circles clearfix">',
      '    <div class="circlesText riskColor">' + place + '</div>',
      '    <div class="bigCircle riskbgc"></div>',
      '    <div class="circlesLine riskbgc"></div>'
    ].join("");
    if (num != 0) {
      earlyWaringRectifyHtml += ['<div class="smallCircleText riskColor">巡检<span>' + num + '</span>次</div>',
        '<div class="smallCircle riskbgc"></div>'
      ].join("");
    }
    earlyWaringRectifyHtml += ['<div class="listDetails">',
      '      <div class="itemDetails">上报时间 : <span>' + date + '</span></div>',
      '      <div class="itemDetails">危险等级 : <span class="highRiskColor">' + rank + '</span></div>',
      '      <div class="itemDetails">上报人 : <span>' + name + '</span></div>',
      '      <div class="rectifyPhotoStyle">',
      '        <ul>' + liHtml + '</ul>',
      '      </div>',
      '    </div>',
      '  </div>',
      '</div>'
    ].join("");
    return earlyWaringRectifyHtml;
  }

  $('#checkEarlyWarningDetails').on('click', '.earlyWaringRectify-trigger', function (event) {
    event.preventDefault();
    $('.earlyWaringRectify-pop').addClass('is-visible3');
    var onlyvalue = seeDetails.data('onlyvalue');
    console.log(onlyvalue)
    // 获取最新的三色预警场所信息
    var ret1 = getThreeColorGetThreeColorWarning({
      onlyValue: onlyvalue
    });
    ret1.then(function (data) {
      console.log(data);
      var data = data.data;
      var appearTimeLast = data.appearTime;
      appearTimeLast = moment(appearTimeLast).format('YYYY-MM-DD HH:mm:ss');
      var rectificationStr = $('#checkEarlyWarningDetails .checkEarlyWarningDetailsLevelisk').val();
      var unit = data.unit;
      var managerStr = data.manager + '/' + data.telephone;

      $('#earlyWaringRectifyModal .textContent .unitStr').text(unit);
      $('#earlyWaringRectifyModal .textContent .people').text(managerStr);
      $('#earlyWaringRectifyModal .textContent .rectification').text(rectificationStr);
      $('#earlyWaringRectifyModal .textContent .date').text(appearTimeLast);
    }).catch(function (err) {
      console.log(err);
    });
    // 将获取的数据每页分为三条
    var ret = getThreeColorGetRectifyByOnlyValue({
      onlyValue: onlyvalue
    });
    ret.then(function (data) {
      console.log(data);
      var data = data.data;
      var resultArr = [];
      // $('.swiper-wrapper').html('');
      // $('.swiper-slide').find('.threeColor').find('.rectifyPhotoStyle li').html('');
      // for (var i = 0; i < data.length; i += 3) {
      //   resultArr.push(data.slice(i, i + 3));
      // }
      $('.swiper-wrapper').html('');
      $('.swiper-slide').find('.threeColor').find('.rectifyPhotoStyle li').html('');
      var mLength = data.length % 3;
      if (mLength == 0) {
        for (var i = 0; i < data.length; i += 3) {
          resultArr.push(data.slice(i, i + 3).reverse());
        }
      } else if (mLength == 1) {
        resultArr.push(data.slice(0, 1));
        for (var i = 1; i < data.length; i += 3) {
          resultArr.push(data.slice(i, i + 3).reverse());
        }
      } else if (mLength == 2) {
        resultArr.push(data.slice(0, 2).reverse());
        for (var i = 2; i < data.length; i += 3) {
          resultArr.push(data.slice(i, i + 3).reverse());
        }
      }
      // var appearTimeLast = seeDetails.parent().siblings().eq(8).text();
      // var rectificationStr = seeDetails.parent().siblings().eq(7).text();
      // var unit = seeDetails.parent().siblings().eq(3).text();
      // var manager = seeDetails.parent().siblings().eq(2).text();
      // var unit = seeDetails.parent().siblings().eq(7).text();


      // $('#earlyWaringRectifyModal .textContent .unitStr').text(unit);
      // $('#earlyWaringRectifyModal .textContent .people').text(manager);
      // $('#earlyWaringRectifyModal .textContent .rectification').text(rectificationStr);
      // $('#earlyWaringRectifyModal .textContent .date').text(appearTimeLast);
      console.log(resultArr);
      var patrolSum = data.length;
      for (var i = 0; i < resultArr.length; i++) {
        $('.swiper-wrapper').append('<div class="swiper-slide"><div class="threeColor"></div></div>');
        for (var j = 0; j < 3; j++) {
          if (resultArr[i][j]) {
            var num = resultArr[i][j].count;
            var appearTime = resultArr[i][j].threeColorWarning.appearTime;
            appearTime = moment(appearTime).format('YYYY-MM-DD HH:mm:ss');
            var appearPeople = resultArr[i][j].threeColorWarning.appearPeople;
            var levelisk = resultArr[i][j].threeColorWarning.levelisk;
            var leveliskStr = '';
            patrolSum += num;
            if (levelisk == 3) {
              leveliskStr = '高危';
            } else if (levelisk == 2) {
              leveliskStr = '较大';
            } else if (levelisk <= 1) {
              leveliskStr = '一般';
            }
            // 整改过程渲染图片
            var imgurlArr = [];
            imgurlArr = resultArr[i][j].url;
            console.log(imgurlArr)
            var liHtml = '';
            if (imgurlArr) {
              for (var k = 0; k < imgurlArr.length; k++) {
                liHtml += '<li><a href="' + imgurlArr[k] + '" class="galpop" data-galpop-group="gallery"><img class="pic img-responsive opacity1" src="' + imgurlArr[k] + '"></a></li>';
              }
            }

            $('.swiper-slide').eq(i).find('.threeColor').append(earlyWaringRectifyHtmlFunc(levelisk, num, appearTime, leveliskStr, appearPeople, liHtml));


          }
        }
      }
      $('#earlyWaringRectifyModal .textContent .sum').text(patrolSum + '次');

      var swiper = new Swiper('.swiper-container', {
        navigation: {
          prevEl: '.swiper-button-next',
          nextEl: '.swiper-button-prev',
        },
      });

      $('.galpop').galpop();
    }).catch(function (err) {
      console.log(err);
    });

  });
});